package com.mvp.shq.washer.view.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mvp.shq.washer.R;


public class QrcodeDialog extends Dialog {

    public QrcodeDialog(Context context) {
        super(context);
    }
    public QrcodeDialog(Context context, int theme) {
        super(context, theme);
    }

    public static class Builder {
        private String message;
        private View layout;
        private QrcodeDialog dialog;
        public Builder(Context context) {
            //这里传入自定义的style，直接影响此Dialog的显示效果。style具体实现见style.xml
            dialog = new QrcodeDialog(context, R.style.Dialog);
            dialog.setCancelable(false);
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = inflater.inflate(R.layout.dialog_qrcode, null);
            dialog.addContentView(layout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }

        public Builder setMessage(String message) {
            this.message = message;
            return this;
        }


        /**
         * 创建单按钮对话框
         * @return
         */
        public QrcodeDialog createSingleButtonDialog() {

//            layout.findViewById(R.id.singleButton).setOnClickListener(singleButtonClickListener);
//            //如果传入的按钮文字为空，则使用默认的“返回”
//            if (singleButtonText != null) {
//                ((Button) layout.findViewById(R.id.singleButton)).setText(singleButtonText);
//            } else {
//                ((Button) layout.findViewById(R.id.singleButton)).setText("返回");
//            }
//            create();
            return dialog;
        }


        /**
         * 单按钮对话框和双按钮对话框的公共部分在这里设置
         */
        private void create() {
//            if (message != null) {      //设置提示内容
//                ((TextView) layout.findViewById(R.id.message)).setText(message);
//            } else if (contentView != null) {       //如果使用Builder的setContentview()方法传入了布局，则使用传入的布局
//                ((LinearLayout) layout.findViewById(R.id.content)).removeAllViews();
//                ((LinearLayout) layout.findViewById(R.id.content))
//                        .addView(contentView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
//            }
//            ImageView imgClose = (ImageView)layout.findViewById(R.id.img_close);
//            imgClose.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    dialog.dismiss();
//                }
//            });
            dialog.setContentView(layout);
            dialog.setCancelable(true);     //用户可以点击手机Back键取消对话框显示
            dialog.setCanceledOnTouchOutside(false);        //用户不能通过点击对话框之外的地方取消对话框显示
        }

    }
}